package com.github.cdisk.xtrans.ui.properties;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * 本地配置文件，用于存储常用配置
 * @author cdisk
 *
 */
public class PropertiesFile {

	public static String get(String key) throws IOException {
		return get(key, null);
	}

	public static String get(String key, String defaultValue) throws IOException {
		File tempProperties = new File(System.getProperty("user.dir") + "/.properties");
		if (!tempProperties.exists()) tempProperties.createNewFile();
		Properties properties = new Properties();
		properties.load(new FileInputStream(tempProperties));
		return properties.getProperty(key, defaultValue);
	}

	public static void put(String key, String value) throws IOException {
		File tempProperties = new File(System.getProperty("user.dir") + "/.properties");
		if (!tempProperties.exists()) tempProperties.createNewFile();
		Properties properties = new Properties();
		properties.load(new FileInputStream(tempProperties));
		properties.setProperty(key, value);
		properties.store(new FileOutputStream(tempProperties), null);
	}

}
